package com.hanbang.baseproject.view.home.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanbang.baseproject.R;
import com.hanbang.baseproject.code.base.view.activity.BaseActivity;
import com.hanbang.baseproject.utils.bitmap.GlideUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.nereo.multi_image_selector.MultiImageSelector;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;

import static com.hanbang.baseproject.view.home.activity.MyActivity.NAME;
import static com.hanbang.baseproject.view.home.activity.MyActivity.NUM;
import static com.hanbang.baseproject.view.home.activity.MyActivity.PICTUE;


/**
 * Created by yang on 2017/5/3 8:05
 */
public class SetActivity extends BaseActivity {


    @BindView(R.id.picture)
    ImageView picture;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.num)
    TextView num;
    ArrayList<String> picturePath = new ArrayList<>();

    public static void startUI(Activity activity) {
        Intent intent = new Intent(activity, SetActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        activity.startActivity(intent);
    }


    @Override
    public int getContentView() {
        return R.layout.activity_set;
    }

    public void initView() {
        toolbar.setTitle("微信");
        toolbar.setBack(this);

    }

    @Override
    public void parseIntent(Intent intent) {

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.llPicture, R.id.llName, R.id.llNum})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.llPicture:
                MultiImageSelector.create()
                        .showCamera(true)
                        .single()
                        .origin(picturePath)
                        .start(this, REQUEST_CODE);

                break;
            case R.id.llName:
                EditActivity.startUI(this, "修改名称",REQUEST_CODE+2);
                break;
            case R.id.llNum:
                EditActivity.startUI(this, "修改微信号",REQUEST_CODE+1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
                picturePath.clear();
                picturePath.addAll(data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT));
                GlideUtils.show(picture, picturePath.get(0));
                PICTUE=picturePath.get(0);
            }

            if (requestCode == REQUEST_CODE+2) {
                name.setText(data.getStringExtra("content"));
                NAME=data.getStringExtra("content");
            }
            if (requestCode == REQUEST_CODE+1) {
                num.setText(data.getStringExtra("content"));
                NUM=data.getStringExtra("content");
            }
        }
    }
}
